package presale_house.handler;

import presale_house.entity.ClientDo;
import presale_house.entity.HouseDo;
import presale_house.service.ClientService;
import presale_house.service.HouseService;
import presale_house.service.impl.ClientServiceImpl;
import presale_house.service.impl.HouseServiceImpl;
import presale_house.show.HouseList.HouseView;
import presale_house.show.MainView;
import presale_house.show.view.AddClientView;
import presale_house.show.view.AddHouseView;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class AddHouseViewHandler implements ActionListener {
    private AddHouseView addHouseView;
    private HouseView houseView;
    public AddHouseViewHandler(AddHouseView addHouseView, HouseView houseView){
        this.addHouseView = addHouseView;
        this.houseView=houseView;
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        JButton jButton=(JButton) e.getSource();
        String text=jButton.getText();
        if("添加".equals(text)){
//            System.out.println("干嘛");
             HouseService houseService =new HouseServiceImpl();
           HouseDo houseDo = addHouseView.buildHouse();
            boolean addResult= houseService.add(houseDo);
            if(addResult){
                //更新表格数据
                houseView.reloadTable();
                JOptionPane.showMessageDialog(addHouseView,"添加成功");
                addHouseView.dispose();
            }else{
                JOptionPane.showMessageDialog(addHouseView,"添加失败");
            }
        }
    }
}
